﻿@ModelType IEnumerable(Of Microsoft.Samples.WindowsPhoneCloud.Web.Models.StorageItemPermissionsModel)
@Code
    ViewData("Title") = "Manage Table Permissions"
End Code
<h2>
    Manage Table Permissions</h2>
<p>
    Select which users can access each table.
</p>
@Code
    Dim users = TryCast(Me.ViewData("users"), IEnumerable(Of Microsoft.Samples.WindowsPhoneCloud.Web.Models.UserModel))
    For Each item In Me.Model
End Code
<div class="storage-heading">
    <div class="public-permissions">
        <input type="hidden" id="Public_@(item.StorageItemName)" value="@(If(item.IsPublic, "true", "false"))" />
        <div class="access-title">
            <span>Table Access: </span><span class="access-value @(If((Not item.IsPublic), "hidden", ""))" id="Public_@(item.StorageItemName)_Public">
                Public</span> <span class="access-value @(If(item.IsPublic, "hidden", ""))" id="Public_@(item.StorageItemName)_Private">
                    Private</span>
        </div>
        &nbsp;&nbsp;
        <div class="access-action">
            (<a onclick="SetPublic('@(item.StorageItemName)', publicActionUrl)"> <span id="Public_@(item.StorageItemName)_SetPublic" class="@(If(item.IsPublic, "hidden", ""))">
                Set Public</span> <span id="Public_@(item.StorageItemName)_SetPrivate" class="@(If((Not item.IsPublic), "hidden", ""))">
                    Set Private</span> </a>)
        </div>
    </div>
    <p class="storage-title">
        Table: <span>@(item.StorageItemName)</span></p>
</div>
<fieldset class="group">
    <legend></legend>
    @Code
            For Each u In users
                Dim containerId = Guid.NewGuid()
                Dim tableChecked = If(item.AllowedUserIds.Contains(u.UserId), "checked=""checked""", String.Empty)
                Dim tableEnabled = If(item.IsPublic, "disabled=""disabled""", String.Empty)
    End Code
    <div class="user">
        <input id="@(item.StorageItemName)_@(containerId)" name="@(item.StorageItemName)_@(containerId)" onclick="SetPermission('@(containerId)', '@(u.UserId)', '@(item.StorageItemName)', addTablePermissionActionUrl, removeTablePermissionActionUrl)"
							type="checkbox" @Me.Html.Raw(tableChecked) @Me.Html.Raw(tableEnabled) />
        <label for="@(item.StorageItemName)_<@(containerId)">
            @(u.UserName)</label>
    </div>
    @Code
            Next u
    End Code
</fieldset>
@Code
    Next item
End Code
<script type="text/javascript">
//<![CDATA[
    var publicActionUrl = '@Me.Html.Raw(Me.Url.Action("SetTablePublic", New With {Key .table = "_storage_", Key .isPublic = "_isPublic_"}))';
    var addTablePermissionActionUrl = '@Me.Html.Raw(Me.Url.Action("AddTablePermission", New With {Key .table = "_storage_", Key .userId = "_user_"}))';
    var removeTablePermissionActionUrl = '@Me.Html.Raw(Me.Url.Action("RemoveTablePermission", New With {Key .table = "_storage_", Key .userId = "_user_"}))';
//]]>
</script>
